package Thread;

import com.sun.xml.internal.ws.addressing.WsaActionUtil;

public class ThreadDemo5 {
    public static void main(String[] args) throws InterruptedException {
        int i = 10;
        Object locker1 = new Object();
        Object locker2 = new Object();
        Thread t1 = new Thread(() -> {
            while(true) {
                synchronized (locker1) {
                    try {
                        locker1.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.println("C");
                }
            }
        } , "a");
        Thread t2 = new Thread(() ->{
            while(true) {
                synchronized (locker2) {
                    try {
                        locker2.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.print("B");
                    synchronized (locker1) {
                        locker1.notify();
                    }
                }
            }
        });
        Thread t4 = new Thread(){
            public void run(){
                System.out.println("1");
            }
        };
        Thread t3 = new Thread(() -> {
            int n = i;
            while(n != 0) {
                synchronized (locker2) {
                    System.out.print("A");
                    locker2.notify();
                    n--;
                    try {
                        locker2.wait(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        });
        t1.start();
        t2.start();
        t3.start();
        Thread.sleep(13000);


    }
}
